package com.example.arithmeticleetcode.leetcode.September;

import java.util.Arrays;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-09-04 10:27
 **/
public class Demo05 {

    public static void main(String[] args) {
        String target1 = "10111";
        String target2 = "001011101";
        String target3 = "00000";
        System.out.println(minFlips(target1));
        System.out.println(minFlips(target2));
        System.out.println(minFlips(target3));

    }

    public static int minFlips(String target) {
        int firstOne = target.indexOf('1');
        if (firstOne == -1) {
            return 0;
        }
        char currentChar = '1';
        int count = 1;
        for (int i = firstOne, len = target.length(); i < len; i++) {
            if (currentChar == target.charAt(i)) {
                continue;
            }
            currentChar = target.charAt(i);
            count ++;

        }
        return count;
    }
}
